package com.payment.ktb.adapter;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;

import com.payment.ktb.R;
import com.payment.ktb.activity.LoginActivity;
import com.payment.ktb.activity.MainActivity;

import java.util.List;

/**
 * Created by syd on 2016/8/3.
 */
public class GuidePagerAdapter extends PagerAdapter {

    View view;
    List<Drawable> listData;
    Context mContext;

    public GuidePagerAdapter(List<Drawable> listData, Context mContext) {
        this.listData = listData;
        this.mContext = mContext;
    }

    @Override
    public int getCount() {
        return listData.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {

        view = LayoutInflater.from(mContext).inflate(R.layout.adapter_guide,null);
        view.setBackgroundDrawable(listData.get(position));
        initView(position);
        container.addView(view);
        return view;
    }

    //初始小点和button按钮
    private void initView(int position) {

        Button btn_guide_confirm = (Button) view.findViewById(R.id.btn_guide_confirm);

        if (position == 0) {
            btn_guide_confirm.setVisibility(View.GONE);
        } else if (position == 1) {
            btn_guide_confirm.setVisibility(View.GONE);
        } else if (position == 2) {
            btn_guide_confirm.setVisibility(View.VISIBLE);
            btn_guide_confirm.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(mContext,LoginActivity.class);
                    mContext.startActivity(new Intent(mContext, MainActivity.class));
                    ((Activity)mContext).finish();
                }
            });
        }

    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }


}
